package xsltrans;

//Based on http://xml.apache.org/xalan-j/usagepatterns.html
//JAXP classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
//JDK classes
import java.io.File;

/**
 * Apply the XSL transform contained in the file named by the first command-line
 * argument to the XML document named by the second argument and write the
 * resulting document to standard output.
 */
class XSLTransform {
	// java XSLTransform HelloWorld.xsl HelloWorld.xml
	public static void main(String args[]) {

		try {
			TransformerFactory tFactory = TransformerFactory.newInstance();
			Transformer transformer = tFactory.newTransformer(new StreamSource(
					new File(args[0]))); 
			transformer.setOutputProperty("indent", "yes");
			long tst = System.currentTimeMillis();
			System.out.println("start at " + tst + "\n"); 
			transformer.transform(new StreamSource(new File(args[1])),
					new StreamResult(System.out)); 
			System.out.println("\nfinished in " + (System.currentTimeMillis()-tst)/1000 + " secs."); 
		} catch (Exception e) {
			e.printStackTrace();
		}
		return;
	}
}
